package dp05.leertaak1.command.implementations;

import dp05.leertaak1.command.definitions.RevertableCommand;
import dp05.leertaak1.dao.definitions.DAO;

public class Insert extends RevertableCommand
{
    private int valueToInsert;

    public Insert(DAO actionReceiver, int value)
    {
        super(actionReceiver);
        this.valueToInsert = value;
    }

    @Override
    public String execute()
    {
        actionReceiver.insert(valueToInsert);
        return String.format("%d inserted", valueToInsert);
    }

    @Override
    public String redo()
    {
        actionReceiver.insert(valueToInsert);
        return String.format("%d re-inserted", valueToInsert);
    }

    @Override
    public String undo()
    {
        Integer removedElement = actionReceiver.removeLast();
        return String.format("%d un-inserted", removedElement);
    }
    
    public String toString()
    {
        return String.format("Insert %d", valueToInsert);
    }
}